#include "../StdInc.h"

namespace GSTrader
{
	namespace TradeBase
	{
		CExchangeStatus::CExchangeStatus() : m_nProviderId(0), m_strExchangeId(""), m_strInstrumentId(""), m_nStatus(exsUnknown), m_nEnterTime(0),
			m_nEnterReason(erUnknown), m_nExchangeId(-1)
		{
		}

		CExchangeStatus::~CExchangeStatus()
		{
		}

		bool CExchangeStatus::HaveStatus()
		{
			return m_nStatus != exsUnknown && m_nEnterTime > 0;
		}

		int CExchangeStatus::GetExchangeIndex()
		{
			if (m_nExchangeId >= 0)
				return m_nExchangeId;

			if (m_strExchangeId.empty())
				return -1;

			string strExchangeId = m_strExchangeId;
			transform(strExchangeId.begin(), strExchangeId.end(), strExchangeId.begin(), tolower);

			for (int x = 0; x < mktCount; x++)
			{
				string strShortName = g_language == slChinese ? Chinese::c_MarketShortName[x] 
					: English::c_MarketShortName[x];
				if (strExchangeId == strShortName)
				{
					m_nExchangeId = x;
					return x;
				}	
			}
			
			assert(false);
			return -1;
		}
	}
}